<!--  -->
<template>
    <div class="view-page">
        <section class="page-hero page-hero_rebrand t-bg t-fg is-layout-split is-size-medium">
            <div class="page-hero__image is-desktop-only">
                <img :src="categoryDetail.pic" loading="lazy">
            </div>
            <!-- <div class="page-hero__content container__tight">

                <h2 class="super-heading"></h2>

                <h1 class="page-hero__title w-0-only right font-extrabold text-2xl">
                    {{ categoryDetail.name }}
                </h1>
                <div class="page-hero__text rte__paragraphs w-0-only font-medium text-base right">
                    <p v-html="categoryDetail.description">
                    </p>
                </div>
            </div> -->
        </section>


        <!-- 产品筛选和列表区域 -->
        <section class="products-section">
            <div class="container">
                <ProductList :showCategory="true" :showLoadMore="showLoadMore" :categoryDetail="categoryDetail"
                    :productList="productList" @loadMoreProducts="loadMoreProducts" />
            </div>
        </section>
        <!-- 内容banner -->
        <ContentBanner />
    </div>
</template>

<script>
import { selectProductCategoryDetail, pageSelectProductList } from "@/config/api";
import ContentBanner from '@/components/content-banner/index.vue';
import ProductList from '@/components/product-list/index.vue';



export default {
    components: {
        ContentBanner,
        ProductList
    },
    data() {
        return {
            categoryDetail: {},
            pageParam: {
                categoryId: null,
                pageNum: 1,
                pageSize: 8,
            },
            showLoadMore: true,
            productList: [],
        };
    },
    mounted() {
        const categoryId = this.$route.query.categoryId;
        if (categoryId) {
            this.pageParam.categoryId = categoryId;
            selectProductCategoryDetail(categoryId).then((res) => {
                if (res.code === 200) {
                    this.categoryDetail = res.data;
                }
            });
            // 筛选产品列表
            this.filterProductList();
        }
    },
    methods: {
        // 筛选产品列表
        filterProductList() {
            pageSelectProductList(this.pageParam).then((res) => {
                if (res.code === 200) {
                    this.productList = [...this.productList, ...res.data.records];
                    const total = res.data.total;
                    this.showLoadMore = total > 4 && this.productList.size < total && total > this.pageParam.pageSize;
                }
            });
        },
        // 加载更多产品
        loadMoreProducts() {
            this.pageParam.pageNum++;
            this.filterProductList();
        },
    },
}
</script>
<style scoped lang="less">
.view-page {
    width: 100%;
}

.page-hero {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 345px;
    background: rgb(39, 70, 58);
}

.page-hero__image {
    width: 100%;
    height: 100%;

    img {
        width: 100%;
        height: 100%;
        object-fit: cover;
        // max-height: 600px;
    }
}

.page-hero__content {
    z-index: 1;
    padding-top: 80px;
    padding-bottom: 80px;
    width: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    // width: 50%;
    padding-left: 124px;
    padding-right: 124px;
    height: 100%;
}

.page-hero__title {
    font-weight: 700;
    font-size: 40px;
    line-height: 1.2;
    color: #F1E5D4;
}

.page-hero__text {
    margin-top: 10px;
    font-weight: 600;
    font-size: 1.125rem;
    line-height: 1.35563rem;
    color: #fff;
}

.products-section {
    padding: 60px 20px;
    background-color: #ffffff;
}

.container {
    max-width: 80%;
    margin: 0 auto;
}
</style>
